package com.burstly.lib.component.networkcomponent.burstly.video;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import com.burstly.lib.component.IBurstlyAdaptor.AdaptorAction;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.activitylauncher.ActivtyLauncher;
import com.burstly.lib.component.activitylauncher.IActivityLauncherSource;
import com.burstly.lib.component.networkcomponent.burstly.AbstractBurstlyAdaptor;
import com.burstly.lib.component.networkcomponent.burstly.BurstlyFullscreenActivity;
import com.burstly.lib.component.networkcomponent.burstly.BurstlyFullscreenConfiguration;
import com.burstly.lib.component.networkcomponent.burstly.FullscreenParams;
import com.burstly.lib.component.networkcomponent.burstly.FullscreenParams.VideoParams;
import com.burstly.lib.network.beans.DestinationType;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.service.SdCardWatchingService;
import com.burstly.lib.util.LoggerExt;
import java.lang.ref.WeakReference;
import java.util.Map;

public final class BurstlyVideoAdaptor extends AbstractBurstlyAdaptor
{
  static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("burstlyVideo", false);
  static final String NETWORK_NAME = "burstlyVideo";
  static BurstlyVideoAdaptor sCurrentInstance;
  String mCacheUrl;
  private boolean mPlayFromCache;
  private VideoCache mVideoCache;
  String mVideoUrl;

  public BurstlyVideoAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " VideoAdaptor");
    SdCardWatchingService.startWatching(paramContext);
    VideoCache.initCache(paramContext);
    this.mVideoCache = VideoCache.getInstance();
    sCurrentInstance = this;
  }

  private FullscreenParams createParametersObject(boolean paramBoolean)
  {
    FullscreenParams localFullscreenParams = new FullscreenParams();
    FullscreenParams.VideoParams localVideoParams = localFullscreenParams.getVideoParams();
    ResponseBean.ResponseData localResponseData = getResponseData();
    localVideoParams.setVideoComponent(new WeakReference(this));
    localVideoParams.setIsPrepared(paramBoolean);
    boolean bool1 = localResponseData.getDestType().equals(DestinationType.DestinationType_custom.getValue());
    String str = localResponseData.getUrl();
    if ((str != null) && (str.startsWith("invalid:")));
    for (int i = 1; ; i = 0)
    {
      boolean bool2;
      if (bool1)
      {
        bool2 = false;
        if (i != 0);
      }
      else
      {
        bool2 = true;
      }
      localVideoParams.setShowVisitButton(bool2);
      Integer localInteger = localResponseData.getSkipButtonActivationTime();
      if (localInteger != null)
        localVideoParams.setShowSkipButtonAfter(Integer.valueOf(1000 * localInteger.intValue()));
      localVideoParams.setMiddleVideoCallback(localResponseData.getValidCbmArray());
      localVideoParams.setEndVideoCallback(localResponseData.getValidCbeArray());
      return localFullscreenParams;
    }
  }

  private static Intent getIntentWithUrl(Intent paramIntent, String paramString)
  {
    paramIntent.putExtra("videoUrl", paramString);
    paramIntent.putExtra("imlementationIdKey", VideoFullscreen.IMPLEMENTATION_ID).addFlags(8388608);
    return paramIntent;
  }

  private void play(boolean paramBoolean)
  {
    this.mPlayFromCache = paramBoolean;
    showActivity(getContext(), this.mTag, this);
  }

  private void showActivity(Context paramContext, String paramString, IActivityLauncherSource paramIActivityLauncherSource)
  {
    if (!isStopped())
      new ActivtyLauncher(paramIActivityLauncherSource, paramContext).setNetworkName("burstlyVideo").setTag(paramString).launchActivity();
  }

  public static boolean showActivity(Context paramContext, String paramString1, FullscreenParams paramFullscreenParams, String paramString2)
  {
    try
    {
      VideoFullscreen.sIsShowingVideoNow = true;
      BurstlyFullscreenConfiguration.setFullscreenParams(paramString1, paramFullscreenParams);
      paramContext.startActivity(getIntentWithUrl(new Intent(paramContext, BurstlyFullscreenActivity.class), paramString1));
      return true;
    }
    catch (ActivityNotFoundException localActivityNotFoundException)
    {
      BurstlyFullscreenConfiguration.removeFullscreenParams(paramString1);
      VideoFullscreen.sIsShowingVideoNow = false;
      LOG.logError(paramString2, "Cannot load Burstly video player. Did you add com.burstly.lib.component.networkcomponent.burstly.BurstlyFullscreenActivity activity to your manifest file?", new Object[0]);
    }
    return false;
  }

  public void beforeLaunch()
  {
    VideoFullscreen.sIsShowingVideoNow = true;
    FullscreenParams localFullscreenParams = createParametersObject(this.mPlayFromCache);
    BurstlyFullscreenConfiguration.setFullscreenParams(this.mVideoUrl, localFullscreenParams);
    IBurstlyAdaptorListener localIBurstlyAdaptorListener = getAdaptorListener();
    if ((localIBurstlyAdaptorListener != null) && (!isStopped()))
    {
      localIBurstlyAdaptorListener.didLoad("burstlyVideo", true);
      localIBurstlyAdaptorListener.shownFullscreen(FULLSCREEN_INFO);
    }
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    super.checkParameters(paramMap);
    ResponseBean.ResponseData localResponseData = getResponseData();
    this.mVideoUrl = localResponseData.getVideoUrl();
    this.mCacheUrl = this.mVideoUrl;
    if (localResponseData.getCachingKey() != null)
      this.mCacheUrl = localResponseData.getCachingKey();
    if ((this.mVideoUrl == null) || (this.mVideoUrl.length() == 0))
      throw new IllegalArgumentException("video url can not be null");
  }

  public void destroy()
  {
    super.destroy();
    sCurrentInstance = null;
  }

  protected View doGetNewAd()
  {
    String str = this.mVideoCache.hasFileInCache(this.mVideoUrl, this.mCacheUrl);
    boolean bool = false;
    if (str != null)
    {
      this.mVideoUrl = str;
      bool = true;
    }
    play(bool);
    return null;
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
  }

  public Intent getIntent()
  {
    return getIntentWithUrl(super.getIntent(), this.mVideoUrl);
  }

  public String getNetworkName()
  {
    return "burstlyVideo";
  }

  public boolean isAllowedToLaunch()
  {
    return !VideoFullscreen.sIsShowingVideoNow;
  }

  public void onActivityNotFound(String paramString)
  {
    VideoFullscreen.sIsShowingVideoNow = false;
    BurstlyFullscreenConfiguration.removeFullscreenParams(this.mVideoUrl);
  }

  public View precacheAd()
  {
    return null;
  }

  public void precacheInterstitialAd()
  {
    getAdaptorListener().didLoad("burstlyVideo", true);
  }

  public void showPrecachedInterstitialAd()
  {
    play(true);
  }

  public boolean supports(String paramString)
  {
    String str = this.mVideoCache.hasFileInCache(this.mVideoUrl, this.mCacheUrl);
    if (str == null)
    {
      if (paramString.equals(IBurstlyAdaptor.AdaptorAction.PRECACHE_INTERSTITIAL.getCode()))
      {
        this.mVideoCache.cacheVideo(this.mVideoUrl, this.mCacheUrl);
        return false;
      }
    }
    else
      this.mVideoUrl = str;
    return true;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.video.BurstlyVideoAdaptor
 * JD-Core Version:    0.6.2
 */